﻿using _2308NA.BLL;
using _2308NA.Model;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace _2308NA.UI.Ajax
{
    /// <summary>
    /// RolesHandler 的摘要说明
    /// </summary>
    public class RolesHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/json";

            string result = "";
            string type = context.Request.QueryString["type"];
            switch (type)
            {
                case "all":
                    result = SelectAll();
                    break;
                default:
                    break;
            }


            context.Response.Write(result);
            context.Response.End();
        }

        //查询所有角色列表
        private static string SelectAll()
        {
            RolesBll bll = new RolesBll();
            List<Roles> list = bll.GetRoles();

            ResultData<List<Roles>> result = new ResultData<List<Roles>>();
            result.code = list.Count() > 0 ? 1 : 0;
            result.msg = list.Count() > 0 ? "ok!" : "null!";
            result.data = list;
            return JsonConvert.SerializeObject(result);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}